﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Basic_dictprojecttype : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindGridView(true);
        }
    }
    public static string strImageUrl(string url0, string url1)
    {
        if (url0.Trim() == string.Empty && url1.Trim() == string.Empty)
            return "缺-L,D";
        else if (url0.Trim() == string.Empty && url1.Trim() != string.Empty)
            return "缺-L";
        else if (url0.Trim() != string.Empty && url1.Trim() == string.Empty)
            return "缺-D";
        else
            return "全";
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bindGridView(false);
    }

    //开始编辑
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bindGridView(false);
        DropDownList ddl = this.GridView1.Rows[e.NewEditIndex].FindControl("DropDownList1") as DropDownList;
        //DropDownList ddl = (DropDownList)(this.GridView1.Rows[e.NewEditIndex].Cells[4].Controls[0]);
        string sqlstr = "select id,tempname from Sys_Template";
        ddl.DataSource = PM.Code.DAL.DbHelper.ExecuteDataReaderBySql(sqlstr);
        ddl.DataBind();
    }
    //编辑结束
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        this.GridView1.EditIndex = -1;
        bindGridView(false);
    }

    protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
    {
        //实例化字典类
        PM.PMBasic.DictData dict = new PM.PMBasic.DictData();
        int id = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
        if (e.CommandName == "delete")
        {
            if (dict.Delete_DictType(id) > 0)
            {
                PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "已删除此申报类别！");
            }
            bindGridView(true);
        }
    }
    //行更新
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //实例化字典类
        PM.PMBasic.DictData dict = new PM.PMBasic.DictData();
        //获取行主键值
        int id = Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Value);
        //获取修改值
        DropDownList ddl = this.GridView1.Rows[e.RowIndex].FindControl("DropDownList1") as DropDownList;
        string templateid = ddl.SelectedValue.Trim();
        dict.Update_DictTemplateType(templateid, id);
        PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "更新成功！");
        this.GridView1.EditIndex = -1;
        bindGridView(false);
    }
    protected void bindGridView(bool GetCount)
    {
        string sqlstr = "select Sys_Guide.id,btnname,btnstate,btnurl0,btnurl1,tempname from Sys_Guide left join Sys_Template on templateid=Sys_Template.id where btnname<>'系统管理'";
        DataTable dt = new DataTable();
        dt = PM.Code.DAL.DbHelper.GetPagedDataTable(sqlstr, 20, AspNetPager1);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}
